package com.yingxin.yxerp.module.easypoi.converter;

import cn.hutool.core.date.DateUtil;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

import java.util.Date;

public class DateTimeConverter implements Converter<Date> {

    private static final String DEFAULT_PATTERN = "yyyy-MM-dd";

    @Override
    public Class supportJavaTypeKey() {
        return null;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return null;
    }

    @Override
    public WriteCellData<?> convertToExcelData(Date value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return null;
    }

    @Override
    public WriteCellData<?> convertToExcelData(WriteConverterContext<Date> context) throws Exception {
        if (null != context.getValue()){
            return new WriteCellData<>(DateUtil.format(context.getValue(),"yyyy年MM月dd日"));
        }else {
            return null;
        }
    }
}
